package Queue;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Queue;

/**
 * Created with IntelliJ IDEA.
 * Description:LinkedList实现链栈，队列
 * User: 阿宾
 * Date: 2024-11-14
 * Time: 10:19
 */
public class Test1 {
    public static void main(String[] args) {
        //Queue是一个接口，所以创建对象的时候需要创建它实现类的对象
        Queue<Integer> queue = new LinkedList<>();//普通队列
        Deque<Integer> deque = new LinkedList<>();//双端队列

        //普通队列操作
        //入队
        queue.offer(1);
        queue.offer(2);
        queue.offer(3);
        //出队
        System.out.println(queue.poll());//1
        System.out.println(queue.poll());//2
        //获取队头元素
        System.out.println(queue.peek());//3
        //获取队列中有效元素个数
        System.out.println(queue.size());//1
        //判断队列是否为空
        System.out.println(queue.isEmpty());//false


    }
    public static void main1(String[] args) {
        LinkedList<Integer> stack = new LinkedList<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        System.out.println(stack.peek());
        stack.pop();
        System.out.println(stack.peek());
    }
}
